package com.hadoop.project.mvc.controller;

import com.hadoop.project.entity.po.Demo;
import com.hadoop.project.entity.query.DemoQuery;
import com.hadoop.project.entity.vo.ResponseVO;
import com.hadoop.project.mvc.service.DemoService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: Controller
 * @author:alexmaodali
 * @date:2025/4/2
 */
@RestController
@RequestMapping("/demo")
public class DemoController extends ABaseController {

	@Resource
	private DemoService demoService;

	/**
	 * 根据条件分页查询
	 */
	@RequestMapping("loadDataList")
	public ResponseVO loadDataList(DemoQuery query) {
		return getSuccessResponseVO(demoService.findListByPage(query));
	}

	/**
	 * 新增
	 */
	@RequestMapping("add")
	public ResponseVO add(Demo bean) {
		this.demoService.add(bean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 批量新增
	 */
	@RequestMapping("addBatch")
	public ResponseVO addBatch(@RequestBody List<Demo> listBean) {
		this.demoService.addBatch(listBean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 批量新增或修改
	 */
	@RequestMapping("addOrUpdateBatch")
	public ResponseVO addOrUpdateBatch(@RequestBody List<Demo> listBean) {
		this.demoService.addOrUpdateBatch(listBean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Id查询
	 */
	@RequestMapping("getDemoById")
	public ResponseVO  getDemoById(Integer id) {
		return getSuccessResponseVO(this.demoService.getDemoById(id));
	}

	/**
	 * 根据Id更新
	 */
	@RequestMapping("updateDemoById")
	public ResponseVO updateDemoById(Demo bean,Integer id) {
		this.demoService.updateDemoById(bean,id);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Id删除
	 */
	@RequestMapping("deleteDemoById")
	public ResponseVO deleteDemoById(Integer id) {
		this.demoService.deleteDemoById(id);
		return getSuccessResponseVO(null);
	}


}
